home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / info / ti734.zip / TI734.TXT
Text File  |  1992-08-12  |  5KB  |  65 lines

  1.  
  2. PRODUCT  :  Borland C++                            NUMBER  :  734             
  3. VERSION  :  2.0                                                               
  4. OS  :  DOS                                                                    
  5. DATE  :  February 25, 1992                        PAGE  :  1/2                
  6.                                                                               
  7. TITLE  :  Determining Stack Size                                              
  8.                                                                               
  9.                                                                               
  10.                                                                               
  11.                                                                               
  12.                                                                               
  13.                                                                               
  14. /************************************************************************     
  15. NEAR MEMORY MODELS:                                                           
  16. In the near memory models the stack resides in the data segment.              
  17. It begins at the end of DGROUP and grows down in memory towards               
  18. SS & DS.  The variable __brklvl always marks the top of the heap.             
  19. The stack is allowed to grow until SP reaches __brklvl at which               
  20. time a stack overflow will be generated if stack checking is                  
  21. turned on else the heap will be overwritten as the stack grows.               
  22.                                                                               
  23.                                                                               
  24. FAR MEMORY MODELS:                                                            
  25. The stack starts in high memory just prior to _heapbase and grows             
  26. down towards SS.                                                              
  27.                                                                               
  28.                                                                               
  29. This code example shows how to check the size of the stack at run             
  30. time.                                                                         
  31.                                                                               
  32.                                                                               
  33. written by:                                                                   
  34. Jerry Shockley    9/18/91                                                     
  35.                                                                               
  36. ************************************************************************/     
  37. #include <stdio.h>                                                            
  38. #include <conio.h>                                                            
  39.                                                                               
  40. unsigned long stack();                                                        
  41.                                                                               
  42. void main()                                                                   
  43. {                                                                             
  44.                                                                               
  45. unsigned long size = stack();                                                 
  46. printf("\nStack size = %lu",size);                                            
  47. }                                                                             
  48.                                                                               
  49. unsigned long stack()                                                         
  50. {                                                                             
  51. unsigned long ret;                                                            
  52. extern unsigned long _heapbase;   //Beginning of the far heap                 
  53. extern  unsigned __brklvl;        //End of the near heap                      
  54. clrscr();                                                                     
  55. #if defined (__COMPACT__) || defined (__LARGE__) || defined                   
  56. (__HUGE__)                                                                    
  57. ret = 16 * (*((unsigned *)_heapbase + 1) - _SS) - 16;                         
  58.                                                                               
  59. #else                                                                         
  60. ret =  *((unsigned *) _heapbase + 1 ) -  __brklvl - 1;                        
  61. #endif                                                                        
  62. return ret;                                                                   
  63. }                                                                             
  64.                                                                               
  65.